package com.ra.util.baidu;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.jsoup.helper.StringUtil;

import com.alibaba.fastjson.JSON;
import com.espirit.https.HttpClientManager;
import com.googlecode.cswish.model.PageInfo;

/**
 * 访问百度地图的工具类, 参见: http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-placeapi
 * 
 * @author lizhongwen
 */
public class BaiduApiUtils {
	
	private static final ObjectMapper mapper = new ObjectMapper();
	
	private static final Log logger = LogFactory.getLog(BaiduApiUtils.class);
	
	// 3ZblpC0ZMvnqUxD0l8CaqsjU
	// A01450a82424c8d995e3ae3ceaf96c40
	// LPDdjSjva5QNAV0VULjUtR9c
	private static String API_KEY = "LPDdjSjva5QNAV0VULjUtR9c";
	
	private static final String API_KEY_BAK = "3ZblpC0ZMvnqUxD0l8CaqsjU";
	
	private static final String GEOCODING_API="http://api.map.baidu.com/geocoder/v2/";
	
	private static final String POI_SEARCH = "http://api.map.baidu.com/place/v2/search";
	private static final String POI_SEARCH_DETAIL = "http://api.map.baidu.com/place/v2/detail";
	
	private static final String IP_LOCATION_API="http://api.map.baidu.com/location/ip";
	
	private static final String CHARSET = "UTF-8";
	
	private static final String PLACE_SUGGESTION_API = "http://api.map.baidu.com/place/v2/suggestion";
	private static final String OCR_API = "http://apis.baidu.com/apistore/idlocr/ocr";
	
	private static final String DIRECTION_SEARCH_API = "";
	
	public static BaiduAddress findCoordinateByAddress(String city,String address){
		if (StringUtils.isEmpty(address)) {
			address = city;
		}
		
		String url = null;
		try {
			url = GEOCODING_API+"?ak="+API_KEY+"&output=json&city="+URLEncoder.encode(city, "UTF-8")+"&address="+URLEncoder.encode(address, "UTF-8");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		
		HttpGet get = null;
		HttpClient client = null;
		BaiduAddress addr= null; 
		
		try {
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			if (json.indexOf("location")<0) {
				logger.error("fail to get coordinate for city:" + city +" and address :" + address);
				return addr;
			}
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status!=0) {
				logger.error("fail to get coordinate for city:" + city +" and address :" + address);
				return addr;
			}
			@SuppressWarnings("rawtypes")
			Map result= (Map) properties.get("result");
			if (result!=null && result.get("location")!=null) {
				@SuppressWarnings("rawtypes")
				Map location= (Map) result.get("location");
				addr = new BaiduAddress();
				addr.setCity(city);
				addr.setAddress(address);
				//经度值
				addr.setLongitude((Double) location.get("lng"));
				//纬度值
				addr.setLatitude((Double) location.get("lat"));
				addr.setPrecise((Integer)result.get("precise"));
				addr.setConfidence((Integer)result.get("confidence"));
				addr.setAddressType((String)result.get("level"));
			}
		} catch (Exception e) {
			logger.error("fail to get coordinate for city:" + city +" and address :" + address,e);
			API_KEY = API_KEY_BAK;
		}
		return addr;
	}
	
	public static BaiduAddress findAddressByCoordinate(double longitude,double latitude){
		String url = GEOCODING_API+"?output=json&pois=0&ak="+API_KEY+"&location="+latitude+","+longitude;
		HttpGet get = null;
		HttpClient client = null;
		BaiduAddress addr= null; 
		try {
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			if (json.indexOf("addressComponent")<0) {
				logger.error("fail to get coordinate for longitude:" + longitude +" and latitude :" + latitude);
				return addr;
			}
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status!=0) {
				logger.error("fail to get coordinate for longitude:" + longitude +" and latitude :" + latitude);
				return addr;
			}
			@SuppressWarnings("rawtypes")
			Map result= (Map) properties.get("result");
			if (result!=null && result.get("addressComponent")!=null) {
				@SuppressWarnings("rawtypes")
				Map addressComponents= (Map) result.get("addressComponent");
				addr = new BaiduAddress();
				addr.setProvince((String)addressComponents.get("province"));
				addr.setCity((String)addressComponents.get("city"));
				addr.setDistrict((String)addressComponents.get("district"));
				addr.setStreet((String)addressComponents.get("street"));
				addr.setStreetNumber((String)addressComponents.get("street_number"));
				addr.setAddress((String)properties.get("formatted_address"));
				//经度值
				addr.setLongitude(longitude);
				//纬度值
				addr.setLatitude(latitude);
			}
		} catch (Exception e) {
			logger.error("fail to get coordinate for longitude:" + longitude +" and latitude :" + latitude,e);
			API_KEY = API_KEY_BAK;
		}
		return addr;
	}
	
	/**
	 * 以关键字， 查询某区域的商家总数
	 * 
	 * @param longitude
	 * @param latitude
	 * @param radius
	 * @param keyword
	 * @return 总数
	 */
	public static Integer countAroundByCoordinate(double longitude,double latitude,double radius,String...keyword){
		if (keyword==null || keyword.length==0) {
			return null;
		}
		String query = "";
		for (int i = 0; i < keyword.length; i++) {
			if (i>0) {
				query+="$";
			}
			query+=keyword[i];
		}
		String url = POI_SEARCH+"?output=json&page_size=1&page_num=0&scope=1&ak="+API_KEY+"&location="+latitude+","+longitude+"&radius="+radius+"&query="+query;
		HttpGet get = null;
		HttpClient client = null;
		try {
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			if (json.indexOf("total")<0) {
				logger.error("fail to get "+ query +" for longitude:" + longitude +" and latitude :" + latitude);
				return null;
			}
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status!=0) {
				logger.error("fail to get  get "+ query +" for longitude:" + longitude +" and latitude :" + latitude);
				return null;
			}
			
			return (Integer)properties.get("total");
		} catch (Exception e) {
			logger.error("fail to get coordinate for longitude:" + longitude +" and latitude :" + latitude + ", " + e.getMessage());
			API_KEY = API_KEY_BAK;
		}
		return null;
	}
	
	/**
	 * 以关键字， 查询某区域的商家信息
	 * 
	 * @param longitude
	 * @param latitude
	 * @param pageNo
	 * @param pageSize
	 * @param radius
	 * @param keyword
	 * @return 总数
	 */
	public static PageInfo<BaiduPlaceDetail> searchPlaceByCoordinate(double longitude, double latitude, double radius, int pageNo, int pageSize, String...keyword){
		if (keyword == null || keyword.length == 0) {
			return null;
		}
		
		pageNo--;		// 百度的分页页码，默认为0。 0代表第一页，1代表第二页，以此类推,  如果设置了此字段，则输出结果中含有total字段
		if (pageSize <= 0) {			
			pageSize = 10;
		}
		
		String query = "*";			// StringUtils.join(keyword, '$')
		String tag = StringUtils.join(keyword, ',');
		String url = POI_SEARCH + "?output=json&page_size=" + pageSize + "&page_num=" + pageNo + "&scope=2&ak=" + API_KEY + "&location="
				+ latitude + "," + longitude + "&radius=" + radius + "&query=" + query + "&tag=" + tag;
		HttpGet get = null;
		HttpClient client = null;
		try {
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			if (json.indexOf("total")<0) {
				logger.error("fail to get "+ query +" for longitude:" + longitude +" and latitude :" + latitude);
				return null;
			}
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status!=0) {
				logger.error("fail to get  get "+ query +" for longitude:" + longitude +" and latitude :" + latitude);
				return null;
			}
			
			Integer total = (Integer)properties.get("total");
			List<Map<String, Object>> results = (List<Map<String, Object>>) properties.get("results");
			PageInfo<BaiduPlaceDetail> pageInfo = new PageInfo<>();
			List<BaiduPlaceDetail> data = new ArrayList<BaiduPlaceDetail>();
			pageInfo.setData(data);
			for (Map<String, Object> item : results) {
				BaiduPlaceDetail baiduPlaceDetail = new BaiduPlaceDetail();
				data.add(baiduPlaceDetail);
				
				baiduPlaceDetail.setId((String) item.get("uid"));
				baiduPlaceDetail.setName((String) item.get("name"));
				baiduPlaceDetail.setAddress((String) item.get("address"));
				baiduPlaceDetail.setTelephone((String) item.get("telephone"));
				baiduPlaceDetail.setStreetId((String) item.get("street_id"));
				
				Map<String, Object> location = (Map<String, Object>) item.get("location");
				baiduPlaceDetail.setLatitude((Double) location.get("lat"));
				baiduPlaceDetail.setLongitude((Double) location.get("lng"));
				
				// detail_url=xxx, overall_rating=1.4, service_rating=0, environment_rating=0, image_num=2, comment_num=0
				Map<String, Object> detail = (Map<String, Object>) item.get("detail_info");
				baiduPlaceDetail.setTag((String) detail.get("tag"));
				// TODO: 从detail_url中取得商户的图片
			}
			pageInfo.setTotalCount(total);
			pageInfo.setPageNo(pageNo + 1);		// pageInfo的pageNo从1开始
			pageInfo.setPageSize(pageSize);
			return pageInfo;
		} catch (Exception e) {
			logger.error("fail to get coordinate for longitude:" + longitude +" and latitude :" + latitude + ", " + e.getMessage());
			// 切换KEY
			logger.info("change api key");
			API_KEY = API_KEY_BAK;
			
		}
		return null;
	}
	
	/**
	 * 以关键字， 查询某区域的商家信息
	 * 
	 * @param longitude
	 * @param latitude
	 * @param pageNo
	 * @param pageSize
	 * @param radius
	 * @param keyword
	 * @return 总数
	 */
	public static BaiduPlaceDetail getDetailPlace(String uid){
		String url = POI_SEARCH_DETAIL + "?output=json&scope=2&ak=" + API_KEY + "&uid=" + uid;
		HttpGet get = null;
		HttpClient client = null;
		try {
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status != 0) {
				logger.error("fail to getDetailPlace for uid: " + uid);
				return null;
			}
			
			
			BaiduPlaceDetail baiduPlaceDetail = new BaiduPlaceDetail();
			Map<String, Object> item = (Map<String, Object>) properties.get("result");
			baiduPlaceDetail.setId((String) item.get("uid"));
			baiduPlaceDetail.setName((String) item.get("name"));
			baiduPlaceDetail.setAddress((String) item.get("address"));
			baiduPlaceDetail.setTelephone((String) item.get("telephone"));
			
			Map<String, Object> location = (Map<String, Object>) item.get("location");
			baiduPlaceDetail.setLatitude((Double) location.get("lat"));
			baiduPlaceDetail.setLongitude((Double) location.get("lng"));
			
			// detail_url=xxx, overall_rating=1.4, service_rating=0, environment_rating=0, image_num=2, comment_num=0
			Map<String, Object> detail = (Map<String, Object>) item.get("detail_info");
			baiduPlaceDetail.setTag((String) detail.get("tag"));
			// TODO: 从detail_url中取得商户的图片
			
			return baiduPlaceDetail;
		} catch (Exception e) {
			logger.error("fail to getDetailPlace for uid: " + uid, e);
			API_KEY = API_KEY_BAK;
		}
		return null;
	}
	
	public static BaiduAddress ipLocation(String ip){
		String url = IP_LOCATION_API+"?coor=bd09ll&ak="+API_KEY+"&ip="+ip;
		HttpGet get = null;
		HttpClient client = null;
		BaiduAddress addr= null; 
		try {
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			if (json.indexOf("content")<0) {
				logger.error("fail to get address for ip:" + ip);
				return addr;
			}
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status!=0) {
				logger.error("fail to get address for ip:" + ip);
				return addr;
			}
			@SuppressWarnings("rawtypes")
			Map result= (Map) properties.get("content");
			if (result!=null && result.get("address_detail")!=null) {
				@SuppressWarnings("rawtypes")
				Map addressDetail= (Map) result.get("address_detail");
				addr = new BaiduAddress();
				addr.setProvince((String)addressDetail.get("province"));
				addr.setCity((String)addressDetail.get("city"));
				addr.setDistrict((String)addressDetail.get("district"));
				addr.setStreet((String)addressDetail.get("street"));
				addr.setStreetNumber((String)addressDetail.get("street_number"));
				addr.setAddress((String)result.get("address"));
				if (result.get("point")!=null) {
					@SuppressWarnings("rawtypes")
					Map point= (Map) result.get("point");
					//经度值
					addr.setLongitude(Double.valueOf((String)point.get("x")));
					//纬度值
					addr.setLatitude(Double.valueOf((String)point.get("y")));
				}
				
			}
		} catch (Exception e) {
			logger.error("fail to get address for ip:" + ip,e);
			API_KEY = API_KEY_BAK;
		}
		return addr;
	}
	
	/**
	 * 根据关键字全国检索地址
	 * @param keyword 关键字
	 * @param region 所属城市/区域名称或代号 
	 * @param output 输出格式 默认是xml格式
	 * @return pageInfo
	 */
	public static PageInfo<BaiduPlaceDetail> searchPlaceByKeyword(String keyword, String region, 
			String output, int pageNo, int pageSize) {
		if(StringUtil.isBlank(keyword)) {
			return null;
		}
		if (StringUtils.isEmpty(region)) {
			region = "全国";
		}
		
		HttpGet get = null;
		HttpClient client = null;
		try {
			String encodeKeyword = URLEncoder.encode(keyword, "utf-8");
			String url = PLACE_SUGGESTION_API + "?query=" + encodeKeyword + "&region=" + region + "&output=json&ak=" + API_KEY;
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status!=0) {
				logger.error("fail to searchPlaceByKeyword by keyword:" + keyword);
				return null;
			}
			
			List<Map<String, Object>> results = (List<Map<String, Object>>) properties.get("result");
			Integer total = results.size();
			if (total == 0) {
				int lastIndex = keyword.length() - 1;
				char[] checkWords = new char[] {'路', '道', '区', '乡', '镇', '县', '市'};
				int index = -1;
				for (int i = 0; i < checkWords.length; i++) {
					char c = checkWords[i];
					index = keyword.lastIndexOf(c, lastIndex);
					if (index != -1) {
						if (index == lastIndex) {
							index--;		// avoid dead cycle
						}
						break;
					}
				}
				
				if (index != -1) {
					PageInfo<BaiduPlaceDetail> pageInfo = searchPlaceByKeyword(keyword.substring(0, index + 1), region, output, pageNo, pageSize);
					if (pageInfo.getData().size() >= 1) {
						pageInfo.getData(0).setName(keyword.substring(index + 1));
					}
					return pageInfo;
				}
			}
			
			PageInfo<BaiduPlaceDetail> pageInfo = new PageInfo<>();
			List<BaiduPlaceDetail> data = new ArrayList<BaiduPlaceDetail>();
			pageInfo.setData(data);
			for (Map<String, Object> item : results) {
				BaiduPlaceDetail baiduPlaceDetail = new BaiduPlaceDetail();
				data.add(baiduPlaceDetail);
				
				baiduPlaceDetail.setName((String) item.get("name"));
				baiduPlaceDetail.setProvince((String)item.get("province"));
				baiduPlaceDetail.setCity((String) item.get("city"));
				baiduPlaceDetail.setDistrict((String) item.get("district"));
				
				Map<String, Object> location = (Map<String, Object>) item.get("location");
				if (location != null) {
					baiduPlaceDetail.setLatitude((Double) location.get("lat"));
					baiduPlaceDetail.setLongitude((Double) location.get("lng"));
				}
			}
			pageInfo.setTotalCount(total);
			pageInfo.setPageNo(pageNo + 1);		// pageInfo的pageNo从1开始
			pageInfo.setPageSize(pageSize);
			return pageInfo;
		} catch (Exception e) {
			logger.error("fail to searchPlaceByKeyword for keyword: " + keyword, e);
			API_KEY = API_KEY_BAK;
		}
		return null;
	}
	
	public static String ocr2(String base64JpgImage) {
		String word = null;
		try {
			String url = OCR_API;
			HttpClient client =  HttpClientBuilder.create().build();
			HttpPost post = HttpClientManager.getPostMethod(url);
			post.addHeader("apikey", "d41d8cd98f00b204e9800998ecf8427e");
			
			List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(2);
			urlParameters.add(new BasicNameValuePair("fromdevice", "pc"));
			urlParameters.add(new BasicNameValuePair("clientip", "10.10.10.0"));
			// OCR接口类型，“LocateRecognize”；“Recognize”；“Locate”；“SingleCharRecognize”。
			// LocateRecognize:整图文字检测、识别,以行为单位;Locate:整图文字行定位;Recognize:整图文字识别;SingleCharRecognize:单字图像识别
			urlParameters.add(new BasicNameValuePair("detecttype", "LocateRecognize"));
			urlParameters.add(new BasicNameValuePair("imagetype", "1"));
			urlParameters.add(new BasicNameValuePair("image", base64JpgImage));
			
			HttpEntity entity = new UrlEncodedFormEntity(urlParameters);
			post.setEntity(entity);
			HttpResponse response = client.execute(post);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			
			Map<String, Object> result = JSON.parseObject(json, HashMap.class);
			Integer errNum = (Integer) result.get("errNum");
			if (errNum != null && errNum.intValue() == 0) {
				Object data = result.get("retData");
				System.out.println(data);
			}
		} catch (Exception e) {
			logger.error("Failed to check picture",e);
			API_KEY = API_KEY_BAK;
		}
		return word;
	}
	
	public static String ocr(String base64JpgImage) {
		System.out.println(base64JpgImage);
		String httpUrl = OCR_API;
		String httpArg = "fromdevice=pc&clientip=10.10.10.0&detecttype=LocateRecognize&languagetype=CHN_ENG&imagetype=1&image=" + base64JpgImage;
		String jsonResult = request(httpUrl, httpArg);
		
		String word = null;
		Map<String, Object> result = JSON.parseObject(jsonResult, HashMap.class);
		Integer errNum = (Integer) result.get("errNum");
		if (errNum != null && errNum.intValue() == 0) {
			Object data = result.get("retData");
			System.out.println(data);
		}
		return word;
	}
	
	private static String request(String httpUrl, String httpArg) {
	    BufferedReader reader = null;
	    String result = null;
	    StringBuffer sbf = new StringBuffer();

	    try {
	        URL url = new URL(httpUrl);
	        HttpURLConnection connection = (HttpURLConnection) url
	                .openConnection();
	        connection.setRequestMethod("POST");
	        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
	        // 填入apikey到HTTP header
	        connection.setRequestProperty("apikey",  "d41d8cd98f00b204e9800998ecf8427e");
	        connection.setDoOutput(true);
	        connection.getOutputStream().write(httpArg.getBytes("UTF-8"));
	        connection.connect();
	        InputStream is = connection.getInputStream();
	        reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
	        String strRead = null;
	        while ((strRead = reader.readLine()) != null) {
	            sbf.append(strRead);
	            sbf.append("\r\n");
	        }
	        reader.close();
	        result = sbf.toString();
	    } catch (Exception e) {
	        logger.error("invalid request", e);
	    }
	    return result;
	}
	
	public String searchDistanceByDriving(double startLng, double startLat, double endLng, double endLat) {
		HttpGet get = null;
		HttpClient client = null;
		/*try {
			String url = PLACE_SUGGESTION_API + "?query=" + encodeKeyword + "&region=" + region + "&output=json&ak=" + API_KEY;
			client =  HttpClientBuilder.create().build();
			get = HttpClientManager.getGetMethod(url);
			HttpResponse response = client.execute(get);
			String json = EntityUtils.toString(response.getEntity(), CHARSET);
			
			@SuppressWarnings("rawtypes")
			Map properties = mapper.readValue(json, Map.class);
			int status = (int) properties.get("status");
			if (status!=0) {
				logger.error("fail to searchDistanceByDriving");
				return null;
			}
			
			List<Map<String, Object>> results = (List<Map<String, Object>>) properties.get("result");
			Integer total = results.size();
			if (total == 0) {
				
			}
		} catch (Exception e) {
			logger.error("fail to searchDistanceByDriving", e);
		}*/
		return null;
	}

	
	public static void main(String[] args) throws Exception {
//		BaiduAddress address = findCoordinateByAddress("深圳市龙岗区", "坂田侨联东一巷7");
//		System.out.println(address.getLatitude() + "," + address.getLongitude());
//		findAddressByCoordinate(114.04559911745,22.557002633296 );
//		
//		System.out.println(count);
//		//		ipLocation("121.40.126.48");
//		
//		PageInfo<BaiduPlaceDetail> pageInfo = searchPlaceByKeyword("龙岗区", "全国", "json", 1, 10);
//		for(BaiduPlaceDetail model : pageInfo.getData()) {
//			System.out.println(model.getCity() + model.getDistrict() + ":" + model.getName());
//		}
		
		
		PageInfo<BaiduPlaceDetail> pageInfo = searchPlaceByCoordinate(114.143367, 22.552417, 500, 1, 10, "地铁");
		int count = countAroundByCoordinate(114.143367, 22.552417,500,"地铁" );
		/*byte [] bytes = FileUtils.readFileToByteArray(new File("d:/p1.jpg"));
		String base64JpgImage = Base64.encodeBase64String(bytes);
		String word = ocr(base64JpgImage);*/
		System.out.println(pageInfo.getData(0).getName());
		System.out.println(count);
		
		BaiduAddress address = findCoordinateByAddress("湘潭市", "江南秀语商务会所");
		System.out.println("===========" + address.getLongitude() + address.getLatitude());
	}
}
